package com.fichaClinica;
import java.io.BufferedInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;

import android.app.Activity;
import android.app.ProgressDialog;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Bundle;
import android.widget.ImageView;

import com.fichaClinica.R;


public class VisorRadiografia extends Activity  {
	

		
		private String image_URL=""; 
		
		private ProgressDialog mProgressDialog;
		
		 @Override
		    public void onCreate(Bundle savedInstanceState) {
				super.onCreate(savedInstanceState);
				setContentView(R.layout.visor_radiografia);
				
				image_URL=this.getIntent().getExtras().getString("URL_RSS");
				
				
			
				ImageView bmImage = (ImageView) findViewById(R.id.imgView);
				
				
				
				
				
			bmImage.setTag(image_URL);
			
			
			mProgressDialog = new ProgressDialog(this);
			mProgressDialog.setMessage("Descargando...");
			mProgressDialog.setTitle("Progreso");
			mProgressDialog.setCancelable(false);
			
			mProgressDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);

			mProgressDialog.setIndeterminate(false);
			mProgressDialog.setMax(100);
			
				
		//		bmImage.setImageBitmap(new DescargaRadiografiaTask().execute(image_URL)); 
			DescargaRadiografiaTask descargaRadiografia = new DescargaRadiografiaTask();
			descargaRadiografia.execute(bmImage);
				
	/*
				BitmapFactory.Options bmOptions;
				bmOptions = new BitmapFactory.Options();
				bmOptions.inSampleSize = 3;
				Bitmap bm = LoadImage(image_URL, bmOptions);
			

				ImageView bmImage = (ImageView) findViewById(R.id.imgView);
				bmImage.setImageBitmap(bm);

	*/

		 }

			public interface ReadyListener {
				public void ready(String name);
			}


			private Bitmap LoadImage(String URL, BitmapFactory.Options options) {
				Bitmap bitmap = null;
				InputStream in = null;
				try {
					in = OpenHttpConnection(URL);
					
					BufferedInputStream bis = new BufferedInputStream(in);
					bitmap = BitmapFactory.decodeStream(bis);
					in.close();
				} catch (IOException e1) {
				}
				return bitmap;
			}

			
			
			private InputStream OpenHttpConnection(String strURL) throws IOException {
				InputStream inputStream = null;
				URL url = new URL(strURL);
				URLConnection conn = url.openConnection();

				try {
					HttpURLConnection httpConn = (HttpURLConnection) conn;
					httpConn.setRequestMethod("GET");
					httpConn.connect();

					if (httpConn.getResponseCode() == HttpURLConnection.HTTP_OK) {
						inputStream = httpConn.getInputStream();
					}
				} catch (Exception ex) {
				}
				return inputStream;
			}

			
			
			public String getImage_URL() {
				return image_URL;
			}

			public void setImage_URL(String image_URL) {
				this.image_URL = image_URL;
			}
			

		}




